import 'dart:ui' as ui;

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bugly/flutter_bugly.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_ncsjqz_getx/constant/app_info.dart';
import 'package:get/get.dart';

import 'init/init_app.dart';
import 'page/loading/loading_view.dart';
import 'util/logger_util.dart';

void main() {
  FlutterBugly.postCatchedException((){
    runApp(MyApp());
    InitApp.initFlutter();
  });
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final botToastBuilder = BotToastInit();
    return GetMaterialApp(
      title: AppInfo.appTitle,
      theme: ThemeData(
        primaryColor: Colors.white,
      ),
      builder: (context, child) { //do something
        child = botToastBuilder(context,child);
        return child;
      },
      localizationsDelegates: [
        // S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      // supportedLocales: S.delegate.supportedLocales,  //支持的国际化语言
      locale: Locale('zh', ''),                       //当前的语言
      localeListResolutionCallback: (locales, supportedLocales) {
        // 语言回调，可在此处进行语言切换
        logger('$locales',tag: "当前语言环境");
        logger('${ui.window.locale}',tag: "当前设备语言环境");
        return;
      },
      routingCallback: (call){
        // 路由回调 可用于管理路由
        logger('${call}',tag: "routingCallback");
      },
      logWriterCallback: localLogWriter,
      home: LoadingPage(),
    );
  }

  // Get的日志信息
  void localLogWriter(String text, {bool isError = false}) {
    logger(text,tag: "Getx");
    // 在这里把信息传递给你最喜欢的日志包。
    // 请注意，即使enableLog: false，日志信息也会在这个回调中被推送。
    // 如果你想的话，可以通过GetConfig.isLogEnable来检查这个标志。
  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }
}
